package com.woniuxy.order.controller;


import com.woniu.commons.util.JwtUtil;
import com.woniu.zsd.commons.core.model.Result;
import com.woniuxy.order.entity.Comment;
import com.woniuxy.order.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import zsd.waste.dto.CommentDto;
import zsd.waste.dto.OrderInfoDto;
import zsd.waste.form.HuifuCommentForm;
import zsd.waste.form.UserInsertCommentForm;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评价模块")
public class CommentController {
    @Resource
    private ICommentService commentService;
    @Resource
    private JwtUtil jwtUtil;

    /**
     * 用户新增评价
     *
     * @return
     */
    @PostMapping("/UserInsertComment")
    @ApiOperation("用户新增评价")
    public Result UserInsertComment(@RequestBody UserInsertCommentForm form, @RequestHeader String token)throws Exception{
        String id = jwtUtil.parseToken(token).get("id").toString();
        Integer userId = Integer.parseInt(id);
        commentService.UserInsertComment(form,userId);
        return Result.getResult().setMsg("评价成功");
    }


    /**
     * 回复评论
     *
     * @return
     */
    @PostMapping("/HuifuComment")
    @ApiOperation("回复评论")
    public Result HuifuComment(@RequestBody HuifuCommentForm form, @RequestHeader String token)throws Exception{
        String id = jwtUtil.parseToken(token).get("id").toString();
        Integer userId = Integer.parseInt(id);
        commentService.HuifuComment(form,userId);
        return Result.getResult().setMsg("评价成功");
    }


    /**
     * 用户查询自己的评论和回复自己的评论
     *
     * @return
     */
    @PostMapping("/userSelectComment")
    @ApiOperation("用户查询自己的评论和回复自己的评论")
    public Result<List<CommentDto>> userSelectComment(@RequestHeader String token)throws Exception{
        String id = jwtUtil.parseToken(token).get("id").toString();
        Integer userId = Integer.parseInt(id);
       List<CommentDto> list =  commentService.userSelectComment(userId);
        return Result.getListResult(CommentDto.class).setMsg("根据条件查询查询订单成功").setData(list);
    }


    /**
     * 站点查询评价
     *
     * @return
     */
    @PostMapping("/SiteSelectComment")
    @ApiOperation("站点查询评价")
    public Result<List<CommentDto>> SiteSelectComment(@RequestHeader String token)throws Exception{
        String id = jwtUtil.parseToken(token).get("id").toString();
        Integer userId = Integer.parseInt(id);
        List<CommentDto> list =  commentService.SiteSelectComment(userId);
        return Result.getListResult(CommentDto.class).setMsg("根据条件查询查询订单成功").setData(list);
    }

}
